package guitforl.wrappers

import guitforl.traits.UpdateableWidget
import scala.collection.mutable.HashMap
import javax.swing.JPanel

class TabWrapper(private val name: String) extends JPanel {
  private val composites = new HashMap[String, JPanel]
  private val edits = new HashMap[String, EditWrapper]
  private var updatebleWidgets = new HashMap[String, UpdateableWidget]

  def getComposite(compositeName: String) = {
    composites(compositeName)
  }

  def addEdit(edit: EditWrapper) {
    edits += edit.name -> edit    
  }

  def addComposite(compositeName: String, composite: JPanel) {
    composites += compositeName -> composite
  }

  def addUpdatebleWidget(widget: UpdateableWidget): Unit = {
    updatebleWidgets += widget.widgetName -> widget
  }

  def getUpdatebleWidgets() = {
    updatebleWidgets
  }

  override def toString() = {
    edits + "\n" + composites
  }

  def getEdits = edits

  def update(name:String):Unit = updatebleWidgets(name).update

  def updateAll(): Unit = {
    //updatebleWidgets.foreach{ (name:String, widget:guitforl.traits.UpdateableWidget) => widget.update}
    val keys = updatebleWidgets.keySet
    keys.foreach(key => updatebleWidgets(key).update)
  }

}
